package com.cx.dao;

import com.cx.domain.T_Logger;
import com.cx.service.T_Loggerservice;
import com.cx.service.goodsservice;
import com.cx.service.timeservice;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.*;
import org.springframework.stereotype.Component;

import java.lang.reflect.Array;
import java.util.Arrays;
@Component
@Aspect
public class pointcut {
    @Autowired
    private timeservice timeservice;
    @Autowired
    private goodsservice goodsservice;
    @Pointcut("execution(* com.cx.service.goodsservice.insertgoods(..))")
    public void pt3() {}
    @Pointcut("execution(* com.cx.service.goodsservice.deletegoods(..))")
    public void pt4() {}
    @Pointcut("execution(* com.cx.service.goodsservice.updategoods(..))")
    public void pt5() {}
    @After("pt3()")
    public void insert(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        timeservice.insertgoods(goodsservice.selectid(),"插入");
        System.out.println(goodsservice.selectid()+"插入成功");
    }
    @After("pt4()")
    public void delete(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        timeservice.insertgoods((String) args[0],"删除");
        System.out.println(args[0]+"删除成功");
    }
    @After("pt5()")
    public void update(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        timeservice.insertgoods((String) args[0],"修改");
        System.out.println(args[0]+"修改成功");
    }
    @Autowired

    private T_Loggerservice t_loggerservice;
    @Pointcut("execution(* com.cx.service.T_Userservice.*(..))")
    public void pt(){};
    @After("pt()")
    public void add(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        t_loggerservice.insertlogger("T_User");
        System.out.println("---------------------------------------------");
        for(T_Logger t_logger:t_loggerservice.selectall()){
            System.out.println(t_logger);
        }
    }

    @Pointcut("execution(* com.cx.service.userservice.insertuser(..)))")
    public void pt1(){}
    @After("pt1()")
    public void register(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        System.out.println("用户："+args[0]+"注册成功");
    }
    @Pointcut("execution(* com.cx.service.userservice.deleteuser(..)))")
    public void pt2(){}
    @After("pt2()")
    public void logoff(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        System.out.println("用户："+args[0]+"注销成功");
    }
}
